package Thread;

public class ThreadDemo12 {
    private static boolean isQuit = false;
    //引入标志位，结束线程
    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            while (!isQuit){
                System.out.println("我是一个线程，工作中！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程工作完毕");
        });

        thread.start();
        //让线程工作三秒钟
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("结束当前线程");
        isQuit = true;
    }
}
